﻿using Newtonsoft.Json.Linq;
using System.IO;
using wpf_print.data;

namespace wpf_print.utils
{
    internal class CatchMsg
    {
        public static JObject GetCatchMsg(string defaultStr)
        {

            try
            {
                JObject catchContent = new();
                catchContent = JObject.Parse(File.ReadAllText("c:\\cache\\cacheText.txt"));
                return catchContent;
            }
            catch
            {
                FileStream fs = new(@"c:\cache" + @"\cacheText.txt", FileMode.Create);
                StreamWriter sw = new(fs);
                sw.Write(defaultStr);
                sw.Flush();
                sw.Close();
                fs.Close();
                JObject catchContent = JObject.Parse(defaultStr);
                return catchContent;
            }


        }
        public static void SetCatchMsg(string str)
        {

            FileStream fs = new(@"c:\cache" + @"\cacheText.txt", FileMode.Create);
            StreamWriter sw = new(fs);
            sw.Write(str);
            sw.Flush();
            sw.Close();
            fs.Close();


        }
    }
}
